# Load in .csv
setwd("/Users/maia/Library/CloudStorage/OneDrive-UW/CCDL/MGH Research Project")

data <- read.csv("MaiaData_CardSort.csv")

1 Descriptives of Dataset

data %>%
  select(-c(Subject, Sex)) %>%
  psych::describe()
##                vars   n   mean     sd median trimmed    mad     min     max
## Age               1 183  40.05  14.52  38.00   39.22  13.34   10.00   87.00
## IncorRespCount    2 185   1.83   3.12   1.00    1.13   1.48    0.00   19.00
## SymRespCount      3 185  18.10  17.66  12.00   16.96  16.31    0.00   48.00
## TxtRespCount      4 185  28.07  17.95  33.00   28.91  20.76    0.00   48.00
## BiasScore         5 185   0.21   0.76   0.44    0.25   0.77   -1.00    1.00
## Con_RT            6 185 885.79 174.50 866.42  875.88 160.51  529.08 1579.72
## InCon_RT          7 185 987.53 325.00 925.81  946.21 209.20  528.29 2863.08
## Incon.ConRT       8 185 101.74 239.42  46.57   62.58  74.70 -116.09 1902.28
##                  range  skew kurtosis    se
## Age              77.00  0.55     0.20  1.07
## IncorRespCount   19.00  3.35    11.70  0.23
## SymRespCount     48.00  0.45    -1.49  1.30
## TxtRespCount     48.00 -0.31    -1.61  1.32
## BiasScore         2.00 -0.38    -1.55  0.06
## Con_RT         1050.64  0.63     0.59 12.83
## InCon_RT       2334.79  2.91    13.12 23.89
## Incon.ConRT    2018.37  5.34    33.94 17.60

2 Distributions of Bias Scores

biasMean <- mean(data$BiasScore, na.rm = T)
biasMedian <- median(data$BiasScore, na.rm = T)

bias1sd <- biasMean + sd(data$BiasScore)
biasneg1sd <- biasMean - sd(data$BiasScore)


data %>%
  ggplot(aes(x=BiasScore)) +
  geom_histogram(fill = "grey", color = "black") +
  geom_vline(mapping = aes(xintercept = biasMean), color = "red", linetype = "dashed", size = 1) +
  geom_vline(mapping = aes(xintercept = biasMedian), color = "blue", linetype = "dashed", size = 1) +
   geom_vline(mapping = aes(xintercept = bias1sd), color = "black", linetype = "dashed", size = 1) +
   geom_vline(mapping = aes(xintercept = biasneg1sd), color = "black", linetype = "dashed", size = 1) +
  ggtitle("Distribution of Bias Scores")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

data %>%
  ggplot(aes(x=BiasScore)) +
  geom_density(fill = "grey", color = "black") +
   geom_vline(mapping = aes(xintercept = biasMean), color = "red", linetype = "dashed", size = 1) +
  geom_vline(mapping = aes(xintercept = biasMedian), color = "blue", linetype = "dashed", size = 1) +
  ggtitle("Distribution of Bias Scores")

#A lot less neutral people than biased people

3 Distributions of Incongruency Effect - Whole Group & Bias Split

# Whole group distribution of incongruency effect

data %>%
  ggplot(aes(x=Incon.ConRT)) +
  geom_histogram(fill = "grey", color = "black") +
  ggtitle("Distribution of Incongruency Rt Effects")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

data %>%
  ggplot(aes(x=InCon_RT)) +
  geom_histogram(fill = "grey", color = "black") +
  ggtitle("Distribution of Incongruency RT")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

data %>%
  ggplot(aes(x=Con_RT)) +
  geom_histogram(fill = "grey", color = "black") +
  ggtitle("Distribution of Congruency RT")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

# Split groups based on bias score
biased <- subset(data, data$BiasScore > 0.8 | data$BiasScore < -0.55)
neutral <- subset(data, data$BiasScore <= 0.8 & data$BiasScore >= -0.55)

biased$Group = "biased"
neutral$Group = "neutral"

data_grouped <- rbind(biased, neutral)

data_grouped %>%
  ggplot(aes(x = BiasScore, fill = Group))+
  geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

data_grouped %>%
  ggplot(aes(x = Incon.ConRT, fill = Group, color = Group))+
  geom_density(alpha = 0.3)+
  ggtitle("Distribution of Incongruency RT Effects By Bias Group Split")

data_grouped %>%
  ggplot(aes(x = InCon_RT, fill = Group, color = Group))+
  geom_density(alpha = 0.3)+
  ggtitle("Distribution of Incongruent RT By Bias Group Split")

data_grouped %>%
  ggplot(aes(x = Con_RT, fill = Group, color = Group))+
  geom_density(alpha = 0.3)+
  ggtitle("Distribution of Congruent RT By Bias Group Split")

#Incongruency RT Effect Dist: Most people have an incongruency effect of 0 or > so, as expected, incongruent trial reaction times are generally greater than congruent trial reaction times. Slight right skew that is made extreme by outliers- will reexamine with outliers removed. #Distribution of Incongruency Effect by Bias Group Split: There are more people who have a lower incongruency effect in the biased attender group than in the neutral attender group. Neutral attender group has a lot less people but its density is a lot more spread out while biased attender incongruency effect has a lot less range and is more concentrated near 0. #Congruent and Incongruent Distributions by Bias Group Split: Biased group seems to be taking less time than the neutral group in both trial types. Could be indication of biased attenders mainly paying attention to their preferred information processing style and ignoring the other stimulus so RTs are faster in both trial types.

4 Reaction times by trial type and attention

# Load necessary libraries
library(tidyverse)
library(ggplot2)
library(reshape2) 

data$Attention <- ifelse(data$BiasScore > 0.8 | data$BiasScore < -0.55, "Biased", "Neutral")
data$IPS <- ifelse(data$BiasScore > 0, "Verbal", "Visual")

#Reaction times
#Biased attender histograms and descriptive statistics
biased_data<- data[data$Attention == "Biased", ]
neutral_data<- data[data$Attention == "Neutral", ]

# Combine biased and neutral data
data$Attention <- ifelse(data$BiasScore > 0.8 | data$BiasScore < -0.55, "Biased", "Neutral")
biased_data<- data[data$Attention == "Biased", ]
combined_data <- rbind(biased_data, neutral_data)

# Calculate means by attention and trial type
means <- combined_data %>%
  group_by(Attention) %>%
  summarise(Con_RT = mean(Con_RT), InCon_RT = mean(InCon_RT)) %>%
  pivot_longer(cols = c(Con_RT, InCon_RT), names_to = "Trial_Type", values_to = "RT")

# Order factor levels for better plotting
means$Attention <- factor(means$Attention, levels = unique(means$Attention))

combined_long <- combined_data %>%
  select(Attention, InCon_RT, Con_RT) %>%
  pivot_longer(cols = c(InCon_RT, Con_RT), values_to = "RT", names_to = "Condition")

# Creat error bars
se_sum <- combined_long %>%
  group_by(Attention, Condition) %>%
  summarise(
    sd = sd(RT),
    n = n(),
    mean = mean(RT)
  ) %>%
  mutate(se = sd/sqrt(n))
## `summarise()` has grouped output by 'Attention'. You can override using the
## `.groups` argument.
# Create bar plot

ggplot(se_sum, aes(x = Attention, y = mean, fill = Condition)) +
  geom_bar(position = position_dodge(0.8), stat = "identity", color = "black", size = 0.5, width = 0.8, alpha = 0.8) +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se), position = position_dodge(0.8), width = 0.25, color = "black") +
  labs(title = "Mean Reaction Times by Attention and Trial Type",
       x = "Attention",
       y = "Mean Reaction Time (ms)") +
  theme_minimal()

#incon rts are larger overall, but the difference between incon and con trial rts for the biased group is a lot smaller than the neutral group- perhaps because the neutral group is noticing both stimuli more? #figure out how to put error bars

5 Incongruency Effect Analysis

5.1 Incongruency Effect Descriptives

# Incongruency Effect Calculation
data$IncongruencyEffect <- data$InCon_RT - data$Con_RT
Incongruency_Effect_Data <- data$IncongruencyEffect

biased_data$Incongruency_Effect_Data <- biased_data$InCon_RT - biased_data$Con_RT
neutral_data$Incongruency_Effect_Data <- neutral_data$InCon_RT - neutral_data$Con_RT

5.1.1 Biased group descriptives

psych::describe(biased_data$Incongruency_Effect_Data)
##    vars   n  mean     sd median trimmed   mad     min    max  range skew
## X1    1 129 55.46 103.18  29.22   43.38 56.63 -114.36 640.06 754.42  2.5
##    kurtosis   se
## X1    10.18 9.08

5.1.2 Neutral group descriptives

psych::describe(neutral_data$Incongruency_Effect_Data)
##    vars  n   mean    sd median trimmed    mad     min     max   range skew
## X1    1 56 208.34 387.8  97.56  128.95 123.32 -116.09 1902.28 2018.37 3.28
##    kurtosis    se
## X1    10.56 51.82
# Biased Attender Incongruency Effect Descriptive Statistics
biased_IE_mean <- mean(biased_data$Incongruency_Effect_Data)
biased_IE_std <- sd(biased_data$Incongruency_Effect_Data)
biased_IE_min <- min(biased_data$Incongruency_Effect_Data)
biased_IE_max <- max(biased_data$Incongruency_Effect_Data)

# Data frame for Biased Attender Incongruency Effect Descriptive Statistics
biased_descriptive_IE <- data.frame(
  Attention = "Biased",  
  Variable = "Incongruency Effect",
  Mean = biased_IE_mean,
  StdDev = biased_IE_std,
  Min = biased_IE_min,
  Max = biased_IE_max,
  stringsAsFactors = FALSE
)

# Neutral Attender Incongruency Effect Descriptive Statistics
neutral_IE_mean <- mean(neutral_data$Incongruency_Effect_Data)
neutral_IE_std <- sd(neutral_data$Incongruency_Effect_Data)
neutral_IE_min <- min(neutral_data$Incongruency_Effect_Data)
neutral_IE_max <- max(neutral_data$Incongruency_Effect_Data)

# Data frame for Neutral Attender Incongruency Effect Descriptive Statistics
neutral_descriptive_IE <- data.frame(
  Attention = "Neutral",  
  Variable = "Incongruency Effect",
  Mean = neutral_IE_mean,
  StdDev = neutral_IE_std,
  Min = neutral_IE_min,
  Max = neutral_IE_max,
  stringsAsFactors = FALSE
)

descriptive_statistics_IE <- rbind(biased_descriptive_IE, neutral_descriptive_IE)
print(descriptive_statistics_IE)
##   Attention            Variable      Mean   StdDev       Min       Max
## 1    Biased Incongruency Effect  55.45634 103.1838 -114.3611  640.0625
## 2   Neutral Incongruency Effect 208.34375 387.7981 -116.0903 1902.2847

5.2 Incongruency Effect Box Plot

# Load necessary libraries
library(ggplot2)

# Combine biased and neutral data for the box plot
combined_data <- rbind(biased_data, neutral_data)

# Create box plot
ggplot(combined_data, aes(x = Attention, y = Incongruency_Effect_Data, fill = Attention)) +
  geom_boxplot() +
  labs(
    title = "Incongruency Effect Box Plot",
    x = "Attention",
    y = "Incongruency Effect (ms)"
  ) +
  scale_fill_manual(values = c("red", "lightblue")) +  # Color for biased and neutral data
  theme_minimal()

## Incongruency Effect Scatter Plot

# Scatter Plot of Incongruency Effect
plot(neutral_data$Incongruency_Effect_Data, 
     col = "blue", 
     pch = 16, 
     main = "Scatter Plot of Incongruency Effect",
     xlab = "Incongruency Effect (ms)",
     ylab = "Condition")

# Adding Biased Attender Data Points
points(biased_data$Incongruency_Effect_Data, 
       col = "red", 
       pch = 16)

6 Individual Differences Analysis

6.1 Correlate Bias score in whole group with incongruency RT effect

cor.test(data$BiasScore, data$Incon.ConRT)
## 
##  Pearson's product-moment correlation
## 
## data:  data$BiasScore and data$Incon.ConRT
## t = -2.6908, df = 183, p-value = 0.007789
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.33006526 -0.05228936
## sample estimates:
##        cor 
## -0.1950863
data %>%
  ggplot(aes(x = BiasScore, y = Incon.ConRT)) +
  geom_point(size = 3, alpha = 0.5, fill = "grey") +
  geom_smooth(method = "lm")
## `geom_smooth()` using formula = 'y ~ x'

#doesn’t look like much of a correlation, reexamine with outliers removed.

6.2 T-test code - with full data (keeping outliers)

#   Difference in Incon-Con RT between Attention Groups

biased<- data[data$Attention == "Biased", ]
neutral<- data[data$Attention == "Neutral", ]

#First test normality assumption in Neutral Group
qqnorm(neutral$Incon.ConRT, pch = 1, frame = FALSE, main = "Neutral Group: Incon - Con RT")
qqline(neutral$Incon.ConRT, col = "steelblue", lwd = 2)

shapiro.test(neutral$Incon.ConRT) # Assumption of normality is violated; probably due to outliers
## 
##  Shapiro-Wilk normality test
## 
## data:  neutral$Incon.ConRT
## W = 0.54087, p-value = 5.666e-12
#Then test normality assumption in Biased Group
qqnorm(biased$Incon.ConRT, pch = 1, frame = FALSE, main = "Biased Group: Incon - Con RT")
qqline(biased$Incon.ConRT, col = "darkred", lwd = 2)

shapiro.test(biased$Incon.ConRT) # Assumption of normality is marginally violated
## 
##  Shapiro-Wilk normality test
## 
## data:  biased$Incon.ConRT
## W = 0.80037, p-value = 5.813e-12
#Check that the variance does not differ between groups
# Perform Levene's AT_FormTest
print(leveneTest(Incon.ConRT ~ Attention, data = combined_data)) # Variances are marginally different; assumption holds
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value    Pr(>F)    
## group   1  11.734 0.0007576 ***
##       183                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Conduct t-test with equal variance assumption
print(t.test(neutral$Incon.ConRT, biased$Incon.ConRT, var.equal = F)) # T-Test is significant after correwction for unequal variances 
## 
##  Welch Two Sample t-test
## 
## data:  neutral$Incon.ConRT and biased$Incon.ConRT
## t = 2.9059, df = 58.409, p-value = 0.005165
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   47.58875 258.18606
## sample estimates:
## mean of x mean of y 
## 208.34375  55.45634
# test normality
qqnorm(neutral$Con_RT, pch = 1, frame = FALSE, main = "Neutral Group: Con RT")
qqline(neutral$Con_RT, col = "steelblue", lwd = 2)

shapiro.test(neutral$Con_RT) #assumption of normality violated
## 
##  Shapiro-Wilk normality test
## 
## data:  neutral$Con_RT
## W = 0.95196, p-value = 0.02604
qqnorm(biased$Con_RT, pch = 1, frame = FALSE, main = "Biased Group: Con RT")
qqline(biased$Con_RT, col = "darkred", lwd = 2)

shapiro.test(biased$Con_RT)
## 
##  Shapiro-Wilk normality test
## 
## data:  biased$Con_RT
## W = 0.98581, p-value = 0.2009
# check if variance differs between groups
print(leveneTest(Con_RT ~ Attention, data = combined_data)) #assumption of homogeneity violated
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value  Pr(>F)  
## group   1  3.9463 0.04847 *
##       183                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#do t-test
print(t.test(neutral$Con_RT, biased$Con_RT, var.equal = F))
## 
##  Welch Two Sample t-test
## 
## data:  neutral$Con_RT and biased$Con_RT
## t = 4.607, df = 88.23, p-value = 1.368e-05
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   74.53769 187.61745
## sample estimates:
## mean of x mean of y 
##  977.1920  846.1144

7 Removing Outliers InCon RT

Incon_minus3SD <- mean(data$InCon_RT) - (3* sd(data$InCon_RT))
Incon_plus3SD <- mean(data$InCon_RT) + (3* sd(data$InCon_RT))

data <- data %>%
  mutate(InconOutlier = InCon_RT >= Incon_plus3SD)

outliers_subset = subset(data, data$InconOutlier == TRUE)


data_outliersremoved <- subset(data, data$InconOutlier == FALSE)

7.1 InCon Outliers Removed Descriptives

data_outliersremoved %>%
  select(-c(Subject, Sex)) %>%
  psych::describe()
## Warning in FUN(newX[, i], ...): no non-missing arguments to min; returning Inf
## Warning in FUN(newX[, i], ...): no non-missing arguments to max; returning -Inf
##                    vars   n   mean     sd median trimmed    mad     min     max
## Age                   1 180  39.89  14.54  38.00   38.99  13.34   10.00   87.00
## IncorRespCount        2 182   1.64   2.79   1.00    1.10   1.48    0.00   19.00
## SymRespCount          3 182  18.15  17.80  12.00   17.00  16.31    0.00   48.00
## TxtRespCount          4 182  28.20  18.07  34.50   29.10  18.53    0.00   48.00
## BiasScore             5 182   0.21   0.76   0.48    0.26   0.76   -1.00    1.00
## Con_RT                6 182 882.95 173.93 863.08  872.69 158.80  529.08 1579.72
## InCon_RT              7 182 957.95 230.28 921.78  939.41 209.53  528.29 1815.85
## Incon.ConRT           8 182  74.99 115.71  44.92   59.37  72.71 -116.09  640.06
## Attention*            9 182   1.29   0.46   1.00    1.24   0.00    1.00    2.00
## IPS*                 10 182   1.39   0.49   1.00    1.36   0.00    1.00    2.00
## IncongruencyEffect   11 182  74.99 115.71  44.92   59.37  72.71 -116.09  640.06
## InconOutlier         12 182    NaN     NA     NA     NaN     NA     Inf    -Inf
##                      range  skew kurtosis    se
## Age                  77.00  0.58     0.24  1.08
## IncorRespCount       19.00  3.90    17.10  0.21
## SymRespCount         48.00  0.43    -1.51  1.32
## TxtRespCount         48.00 -0.33    -1.62  1.34
## BiasScore             2.00 -0.38    -1.57  0.06
## Con_RT             1050.64  0.65     0.67 12.89
## InCon_RT           1287.56  0.87     1.00 17.07
## Incon.ConRT         756.15  1.75     4.40  8.58
## Attention*            1.00  0.91    -1.18  0.03
## IPS*                  1.00  0.45    -1.81  0.04
## IncongruencyEffect  756.15  1.75     4.40  8.58
## InconOutlier          -Inf    NA       NA    NA

#now that outliers are removed, incon effect mean went from 101.74 to 74.99.

7.2 Distributions of Incongruency Effect - Whole Group & Bias Split (InCon Outliers Removed)

data_outliersremoved %>%
  ggplot(aes(x=Incon.ConRT)) +
  geom_histogram(fill = "grey", color = "black") +
  ggtitle("Distribution of Incongruency Rt Effects (Outliers Removed)")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

data_outliersremoved %>%
  ggplot(aes(x=InCon_RT)) +
  geom_histogram(fill = "grey", color = "black") +
  ggtitle("Distribution of Incongruency RT (Outliers Removed)")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

data_outliersremoved %>%
  ggplot(aes(x=Con_RT)) +
  geom_histogram(fill = "grey", color = "black") +
  ggtitle("Distribution of Congruency RT (Outliers Removed)")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

biased <- subset(data_outliersremoved, data_outliersremoved$BiasScore > 0.8 | data_outliersremoved$BiasScore < -0.55)
neutral <- subset(data_outliersremoved, data_outliersremoved$BiasScore <= 0.8 & data_outliersremoved$BiasScore >= -0.55)

data_grouped <- rbind(biased, neutral)

data_grouped %>%
  ggplot(aes(x = Incon.ConRT, fill = Attention, color = Attention))+
  geom_density(alpha = 0.3)+
  ggtitle("Distribution of Incongruency RT Effects By Bias Group Split")

data_grouped %>%
  ggplot(aes(x = InCon_RT, fill = Attention, color = Attention))+
  geom_density(alpha = 0.3)+
  ggtitle("Distribution of Incongruent RT By Bias Group Split")

data_grouped %>%
  ggplot(aes(x = Con_RT, fill = Attention, color = Attention))+
  geom_density(alpha = 0.3)+
  ggtitle("Distribution of Congruent RT By Bias Group Split")

# Incon effect dist: Most people seem to fall between 0 and 250 ms incongruency effect- incongruent trials taking longer!

7.3 Reaction times by trial type and attention (InCon Outliers Removed)

data_outliersremoved$Attention <- ifelse(data_outliersremoved$BiasScore > 0.8 | data_outliersremoved$BiasScore < -0.55, "Biased", "Neutral")
data_outliersremoved$IPS <- ifelse(data_outliersremoved$BiasScore > 0, "Verbal", "Visual")

# Reaction times
# Biased attender histograms and descriptive statistics
biased_data <- data_outliersremoved[data_outliersremoved$Attention == "Biased", ]
neutral_data <- data_outliersremoved[data_outliersremoved$Attention == "Neutral", ]

# Combine biased and neutral data
data_outliersremoved$Attention <- ifelse(data_outliersremoved$BiasScore > 0.8 | data_outliersremoved$BiasScore < -0.55, "Biased", "Neutral")
biased_data <- data_outliersremoved[data_outliersremoved$Attention == "Biased", ]
combined_data <- rbind(biased_data, neutral_data)

# Calculate means by attention and trial type
library(dplyr)
library(tidyr)
library(ggplot2)

means <- combined_data %>%
  group_by(Attention) %>%
  summarise(Con_RT = mean(Con_RT, na.rm = TRUE), InCon_RT = mean(InCon_RT, na.rm = TRUE)) %>%
  pivot_longer(cols = c(Con_RT, InCon_RT), names_to = "Trial_Type", values_to = "RT")

# Order factor levels for better plotting
means$Attention <- factor(means$Attention, levels = unique(means$Attention))

combined_long <- combined_data %>%
  select(Attention, InCon_RT, Con_RT) %>%
  pivot_longer(cols = c(InCon_RT, Con_RT), values_to = "RT", names_to = "Condition")

# Create error bars
se_sum <- combined_long %>%
  group_by(Attention, Condition) %>%
  summarise(
    sd = sd(RT, na.rm = TRUE),
    n = n(),
    mean = mean(RT, na.rm = TRUE)
  ) %>%
  mutate(se = sd/sqrt(n))
## `summarise()` has grouped output by 'Attention'. You can override using the
## `.groups` argument.
# Create bar plot
ggplot(se_sum, aes(x = Attention, y = mean, fill = Condition)) +
  geom_bar(position = position_dodge(0.8), stat = "identity", color = "black", size = 0.5, width = 0.8, alpha = 0.8) +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se), position = position_dodge(0.8), width = 0.25, color = "black") +
  labs(title = "Mean Reaction Times by Attention and Trial Type",
       x = "Attention",
       y = "Mean Reaction Time (ms)") +
  theme_minimal()

## Incongruency Effect Box Plot (InCon Outliers Removed)

biased_data<- data_outliersremoved[data_outliersremoved$Attention == "Biased", ]
neutral_data<- data_outliersremoved[data_outliersremoved$Attention == "Neutral", ]

combined_data <- rbind(biased_data, neutral_data)
Incongruency_Effect_Data <- data_outliersremoved$IncongruencyEffect

# Create box plot
ggplot(combined_data, aes(x = Attention, y = Incongruency_Effect_Data, fill = Attention)) +
  geom_boxplot() +
  labs(
    title = "Incongruency Effect Box Plot",
    x = "Attention",
    y = "Incongruency Effect (ms)"
  ) +
  scale_fill_manual(values = c("red", "lightblue")) +  # Color for biased and neutral data
  theme_minimal()

## Bias Score and Incongruency Effect Correlation (InCon Outliers Removed)

data_outliersremoved %>%
  ggplot(aes(x = BiasScore, y = Incon.ConRT)) +
  geom_point(size = 3, alpha = 0.5, fill = "grey") +
  geom_smooth(method = "lm")
## `geom_smooth()` using formula = 'y ~ x'

cor.test(data_outliersremoved$BiasScore, data_outliersremoved$Incon.ConRT)
## 
##  Pearson's product-moment correlation
## 
## data:  data_outliersremoved$BiasScore and data_outliersremoved$Incon.ConRT
## t = -5.5861, df = 180, p-value = 8.46e-08
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.5017781 -0.2530704
## sample estimates:
##        cor 
## -0.3843768

7.4 t-test (InCon Outliers Removed)

t.test(Incon.ConRT~Attention, data=data_outliersremoved)
## 
##  Welch Two Sample t-test
## 
## data:  Incon.ConRT by Attention
## t = -3.3291, df = 79.807, p-value = 0.00132
## alternative hypothesis: true difference in means between group Biased and group Neutral is not equal to 0
## 95 percent confidence interval:
##  -107.18506  -26.98088
## sample estimates:
##  mean in group Biased mean in group Neutral 
##              55.45634             122.53931

8 T-test Code - Removing Incon Outliers

biased_data<- data_outliersremoved[data_outliersremoved$Attention == "Biased", ]
neutral_data<- data_outliersremoved[data_outliersremoved$Attention == "Neutral", ]

qqnorm(neutral_data$Incon.ConRT, pch = 1, frame = FALSE, main = "Neutral Group: Incon - Con RT (Outliers Removed)")
qqline(neutral_data$Incon.ConRT, col = "steelblue", lwd = 2)

shapiro.test(neutral_data$Incon.ConRT)
## 
##  Shapiro-Wilk normality test
## 
## data:  neutral_data$Incon.ConRT
## W = 0.9365, p-value = 0.007351
# Then test normality assumption in Biased Group
qqnorm(biased_data$Incon.ConRT, pch = 1, frame = FALSE, main = "Biased Group: Incon - Con RT (Outliers Removed)")
qqline(biased_data$Incon.ConRT, col = "darkred", lwd = 2)

shapiro.test(biased_data$Incon.ConRT) 
## 
##  Shapiro-Wilk normality test
## 
## data:  biased_data$Incon.ConRT
## W = 0.80037, p-value = 5.813e-12
# Check that the variance does not differ between groups
# Perform Levene's Test
print(leveneTest(Incon.ConRT ~ Attention, data = data_outliersremoved)) 
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value  Pr(>F)  
## group   1  5.5793 0.01924 *
##       180                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Conduct t-test with equal variance assumption
print(t.test(neutral_data$Incon.ConRT, biased_data$Incon.ConRT, var.equal = FALSE)) 
## 
##  Welch Two Sample t-test
## 
## data:  neutral_data$Incon.ConRT and biased_data$Incon.ConRT
## t = 3.3291, df = 79.807, p-value = 0.00132
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   26.98088 107.18506
## sample estimates:
## mean of x mean of y 
## 122.53931  55.45634

9 Removing outliers- Congruent RT

Con_minus3SD <- mean(data_outliersremoved$Con_RT) - (3* sd(data_outliersremoved$Con_RT))
Con_plus3SD <- mean(data_outliersremoved$Con_RT) + (3* sd(data_outliersremoved$Con_RT))

data_outliersremoved <- data_outliersremoved %>%
  mutate(ConOutlier = Con_RT >= Con_plus3SD)

subset(data_outliersremoved, ConOutlier == TRUE)
##      Subject Age Sex IncorRespCount SymRespCount TxtRespCount  BiasScore
## 100 9449a552  57   2             19           17           12 -0.1724138
##       Con_RT InCon_RT Incon.ConRT Attention    IPS IncongruencyEffect
## 100 1579.715 1494.562   -85.15278   Neutral Visual          -85.15278
##     InconOutlier ConOutlier
## 100        FALSE       TRUE
data_final <- subset(data_outliersremoved, ConOutlier == FALSE)

10 T-test with All Outliers Removed

biased_data <- data_final[data_final$Attention == "Biased", ]
neutral_data <- data_final[data_final$Attention == "Neutral", ]

qqnorm(neutral_data$Incon.ConRT, pch = 1, frame = FALSE, main = "Neutral Group: Incon - Con RT (Outliers Removed)")
qqline(neutral_data$Incon.ConRT, col = "steelblue", lwd = 2)

shapiro.test(neutral_data$Incon.ConRT)
## 
##  Shapiro-Wilk normality test
## 
## data:  neutral_data$Incon.ConRT
## W = 0.92908, p-value = 0.004134
# Then test normality assumption in Biased Group
qqnorm(biased_data$Incon.ConRT, pch = 1, frame = FALSE, main = "Biased Group: Incon - Con RT (Outliers Removed)")
qqline(biased_data$Incon.ConRT, col = "darkred", lwd = 2)

shapiro.test(biased_data$Incon.ConRT) 
## 
##  Shapiro-Wilk normality test
## 
## data:  biased_data$Incon.ConRT
## W = 0.80037, p-value = 5.813e-12
# Check that the variance does not differ between groups
# Perform Levene's Test
print(leveneTest(Incon.ConRT ~ Attention, data = data_final)) 
## Warning in leveneTest.default(y = y, group = group, ...): group coerced to
## factor.
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value  Pr(>F)  
## group   1  4.9887 0.02675 *
##       179                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Conduct t-test with equal variance assumption
print(t.test(neutral_data$Incon.ConRT, biased_data$Incon.ConRT, var.equal = FALSE)) 
## 
##  Welch Two Sample t-test
## 
## data:  neutral_data$Incon.ConRT and biased_data$Incon.ConRT
## t = 3.5444, df = 78.651, p-value = 0.000666
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   31.15857 110.99552
## sample estimates:
## mean of x mean of y 
## 126.53339  55.45634